package com.car.controller;


import com.car.model.auto.Role;
import com.car.model.auto.User;
import com.car.service.IRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {

    @Resource
    private IRoleService iRoleService;

    /*查询角色*/
    @GetMapping("/getRole")
    public List<Role> getRole(){
        return iRoleService.list();
    }

    /*通过id查询角色*/
    @GetMapping("/getRoleById/{id}")
    public Role getRoleById(@PathVariable("id") int id){
        return iRoleService.getById(id);
    }

    /*修改角色*/
    @PostMapping("/updateRole")
    public void updateRole(@RequestBody Role role){
        iRoleService.updateById(role);
    }

    /*添加角色*/
    @PostMapping("/setRole")
    public void setRole(@RequestBody Role role){
        iRoleService.save(role);
    }

    /*删除角色*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iRoleService.removeById(id);
    }

}
